
# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def addTwoNumbers(self, l1, l2):
	"""
	:type l1: ListNode
	:type l2: ListNode
	:rtype: ListNode
	"""
	n1 = 0
	n2 = 0

	base = 1
	while l1 != None:
		n1 = n1 + l1.val * base
		l1 = l1.next
		base *= 10
	base = 1
	while l2 != None:
		n2 = n2 + l2.val * base
		l2 = l2.next
		base *= 10

	n = n1 + n2
	res = ListNode(n % 10)
	n /= 10
	listnode = res
	while n != 0:
		listnode.next = ListNode(n % 10)
		n /= 10
		listnode = listnode.next

	return res